<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>JS异步机制在浏览器上的实现过程</title>
</head>
<body>
  <script>
    // Step 1
    console.log(1);

    // Step 2
    setTimeout(() => {
      console.log(2);
      Promise.resolve().then(() => {
        console.log(3);
      });
    }, 0);

    // Step 3
    new Promise((resolve, reject) => {
      console.log(4);
      resolve();
    }).then(() => {
      console.log(5);
    })

    // Step 4
    setTimeout(() => {
      console.log(6);
    }, 0);

    // Step 5
    console.log(7);
  </script>
</body>
</html>